/*
 * Copyright Thoughtworks, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
describe("value_stream_map", function () {
  beforeEach(function () {
    setFixtures(`<div id="vsm-container"></div>`);
  });
  var called;
  beforeEach(function () {
    $('#vsm-container').html("");
    called = false;
  });

  const mockRenderer = function () {
    mockRenderer.prototype.invoke = function (data) {
      called = true;
    };
  };

  it("testShouldRenderGraphIfDataDoesNotHaveError", function () {
    var node1 = '{"node_type":"MATERIAL","name":"../manual-testing/ant_hg/dummy","parents":[],"dependents":["p2"],"id":"hg_fingerprint"}';
    var node2 = '{"node_type":"PIPELINE","name":"p2","parents":["hg_fingerprint"],"dependents":[],"id":"p2"}]}';
    var vsm = eval(`({"current_pipeline":"p2","levels":[{"nodes":[${node1}]},{"nodes":[${node2}]})`);
    new VSM(vsm, "#vsm-container", new mockRenderer()).render();
    expect(called).toBe(true);
  });

  it("testShouldRenderErrorMessageIfVSMHasErrors", function () {
    var unableToFind = `<div class="pagenotfound"><div class="biggest">:(</div><h3>${_.escape("error message")}</h3><span>Go to <a href="/go/pipelines">Pipelines</a></span></div>`;
    var vsm = eval('({"error":"error message"})');
    new VSM(vsm, "#vsm-container", new mockRenderer()).render();
    expect(called).toBe(false);
    expect($("#vsm-container").html()).toBe(unableToFind);
  });
});
